Skip to content

html.global_attributes.contenteditable - Add note about white-space style hack of Chrome/Chromium when contenteditable=plaintext-only #26719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
masayuki-nakano opened this issue May 1, 2025 · 3 comments
Labels
data:html Compat data for HTML elements. https://developer.mozilla.org/docs/Web/HTML p4 Low priority – Community PRs accepted.

Comments

@masayuki-nakano
Copy link

MDN URL

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable

What specific section or headline is this issue about?

"paintext-only" definition in the "Value" section should have a note

What information was incorrect, unhelpful, or incomplete?

Currently, Chrome/Chromium has a hack for white-space style when contenteditable value is plaintext-only. That is, they override the specified (or implicit) white-space style to pre-wrap or pre.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/css/resolver/style_adjuster.cc;l=405-415;drc=3a3c641c8597f54a4eb6286d816f52b8a649c8bf
And they always use \n as a line break instead of <br> and never use NBSPs when user types white-spaces consecutively.

However, this is invalid behavior from CSS spec point of view and this hack leads different result from Firefox and Safari. Firefox and Safari do not override white-space style and use <br> instead when inserting a line break. And also they use pairs of an NBSP and an ASCII space if multiple collapsible white-spaces are typed consecutively. I.e., these behaviors are same as contenteditable=true if white-space style does not preserve line breaks and/or consecutive white-spaces.

In other words, Chrome/Chromium's hack leads web-compat issue between browsers.

If the web app wants to retrieve the input values of contenteditable=plaintext-only with Element.textContent, the web app should specify white-space: pre or white-space: pre-wrap explicitly. Then, web apps do not need to take care of this incompatibility.

What did you expect to see?

So first, there should be a note that explains what Chrome/Chromium does. Their hack makes web apps access the result with Element.textContent easier, but web apps cannot use white-space: normal, etc for plaintext-only.

And then, recommend to specify white-space style to pre-wrap or pre explicitly.

Do you have any supporting links, references, or citations?

Do you have anything more you want to share?

Nothing special.

MDN metadata

Page report details
@masayuki-nakano masayuki-nakano added the needs triage This issue needs to be confirmed label May 1, 2025
@Josh-Cena Josh-Cena removed the needs triage This issue needs to be confirmed label May 1, 2025
@caugner
Copy link
Contributor

caugner commented May 6, 2025

This sounds like we should add notes for this feature's Chrome entry in BCD:

"chrome": {
"version_added": "51"
},

@caugner caugner transferred this issue from mdn/content May 6, 2025
@caugner caugner changed the title Add a note about white-space style hack of Chrome/Chromium when contenteditable=plaintext-only html.global_attributes.contenteditable - Add note about white-space style hack of Chrome/Chromium when contenteditable=plaintext-only May 6, 2025
@queengooborg queengooborg added the data:html Compat data for HTML elements. https://developer.mozilla.org/docs/Web/HTML label May 6, 2025
@caugner
Copy link
Contributor

caugner commented May 7, 2025

@masayuki-nakano Thanks for reporting. Would you like to open a PR adding notes to that Chrome support statement, explalining how white-space styles are replaced with this feature?

"chrome": {
"version_added": "51"
},

(Chromium source code: https://github.com/chromium/chromium/blob/b2acd809f4b4d12c23b9726ccb223d8b8e62baba/third_party/blink/renderer/core/css/resolver/style_adjuster.cc#L408-L415)

@masayuki-nakano
Copy link
Author

Unfortunately, I don't have much time for several weeks, once nobody can do that, I'd try...

@caugner caugner added the p4 Low priority – Community PRs accepted. label May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:html Compat data for HTML elements. https://developer.mozilla.org/docs/Web/HTML p4 Low priority – Community PRs accepted.
Projects
None yet
Development

No branches or pull requests

4 participants